package com.example.a2022180806

import android.annotation.SuppressLint
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import java.util.Locale

//class MainActivity : AppCompatActivity() {
//    @RequiresApi(Build.VERSION_CODES.R)
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()
//        setContentView(R.layout.activity_main)
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
//            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
//            insets
//        }
//        val button1=findViewById<Button>(R.id.button1)
//        button1.setOnClickListener{
//
//        }
//
//    }
//}



class MainActivity : AppCompatActivity() {

//    private var currentLanguage = "en" // 默认语言
//
//    @RequiresApi(Build.VERSION_CODES.R)
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()
//        setContentView(R.layout.activity_main)
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
//            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
//            insets
//        }
//        val button1 = findViewById<Button>(R.id.button1)
//        val textview=findViewById<TextView>(R.id.textView)
//        button1.setOnClickListener {
//            textview.text="I am clicked!"
//        }


    @RequiresApi(Build.VERSION_CODES.R)
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val button= findViewById<Button>(R.id.button1)
        val textView= findViewById<TextView>(R.id.textView)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        button.setOnClickListener{
            textView.text=getString(R.string.clicked)
        }
    }


    }





//    private fun changeLanguage() {
//        when (currentLanguage) {
//            "en" -> {
//                currentLanguage = "es"
//                updateLanguage("es")
//            }
//            "es" -> {
//                currentLanguage = "zh"
//                updateLanguage("zh")
//            }
//            "zh" -> {
//                currentLanguage = "en"
//                updateLanguage("en")
//            }
//        }
//    }

//    private fun updateLanguage(languageCode: String) {
//        val locale = Locale(languageCode)
//        Locale.setDefault(locale)
//        val resources = resources
//        val packageName = packageName
//        val context = createConfigurationContext(Configuration(resources.configuration))
//        context.setLocale(locale)
//        resources.updateConfiguration(resources.configuration, resources.displayMetrics)
//        recreate() // 重新创建活动以应用新的语言
//    }


